import javax.swing.*;
import java.awt.*;

public class ScrollablePanelExample {
    public static void main(String[] args) {
        JFrame frame = new JFrame("可滚动的面板示例");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 200);

        // 创建一个内容较大的 JPanel
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new GridLayout(20, 1));
        for (int i = 0; i < 20; i++) {
            JLabel label = new JLabel("Label " + (i+1));
            contentPanel.add(label);
        }

        // 创建一个滚动面板，并将 JPanel 添加进去
        JScrollPane scrollPane = new JScrollPane(contentPanel);

        frame.getContentPane().add(scrollPane);
        frame.setVisible(true);
    }
}
